package controller

import (
	"gin-rkboot-sw/internal/common"
	"github.com/gin-gonic/gin"
)

var (
	Greeter = cGreeter{}
)

type cGreeter struct{}

// Hello handler
// @Summary Greeter
// @Id 1
// @Tags Hello
// @version 1.0
// @Param name query string false "name"
// @produce application/json
// @Success 200 map[string]interface{}
// @Router /v1/greeter [get]
func (c *cGreeter) Hello(ctx *gin.Context) {
	builder := common.NewResponseBuilder[any](ctx)
	builder.Message(ctx.Query("name")).Response()
}

// PostApi handler
// @Summary Greeter
// @Id 2
// @Tags Hello
// @version 1.0
// @Param name body controller.Res false "name"
// @produce application/json
// @Success 200 map[string]interface{}
// @Router /v1/greeter_post [post]
func (c *cGreeter) PostApi(ctx *gin.Context) {
	responseBuilder := common.NewResponseBuilder[string](ctx)
	res := Res{}
	err := ctx.Bind(&res)
	if err != nil {
		responseBuilder.ErrorMessage(err).Response()
	} else {
		responseBuilder.Data(res.Name).Response()
	}

}

type Res struct {
	Name string `json:"name"`
}
